Skip to content

Conversation

Flo0807
Copy link
Collaborator

@Flo0807 Flo0807 commented Jul 18, 2025

closes #1280

@Flo0807 Flo0807 self-assigned this Jul 18, 2025
@Flo0807 Flo0807 added the breaking-change A breaking change label Jul 18, 2025
@Flo0807 Flo0807 marked this pull request as draft July 18, 2025 12:14
@Flo0807 Flo0807 force-pushed the feature/1280-improve-currency-field branch from 05f2d56 to 1f67ccd Compare August 8, 2025 07:48
@Flo0807 Flo0807 changed the base branch from develop to feature/js-bundle August 8, 2025 07:51
@Flo0807 Flo0807 changed the base branch from feature/js-bundle to develop August 8, 2025 07:52
@Flo0807 Flo0807 changed the base branch from develop to feature/js-bundle August 8, 2025 07:53
@Flo0807 Flo0807 force-pushed the feature/1280-improve-currency-field branch 2 times, most recently from 1f67ccd to c212eae Compare August 8, 2025 12:27
@Flo0807 Flo0807 requested a review from Copilot August 8, 2025 12:35
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the Backpex.Fields.Currency field by replacing the internal Money library implementation with a more flexible masked number input approach. The changes allow users to provide their own Money library configuration while maintaining proper currency formatting in forms.

Key changes:

  • Removes the internal Backpex.Ecto.Amount.Type and switches to external Money library usage
  • Introduces a new masked number input component with IMask.js integration
  • Adds configurable currency formatting options (unit, position, separators)

Reviewed Changes

Copilot reviewed 12 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/backpex/fields/currency.ex Updated to use masked input instead of number input, added configuration options for currency formatting
lib/backpex/html/form.ex Added new masked_number_input component with IMask integration
assets/js/hooks/_masked_number_input.js New JavaScript hook implementing IMask for currency formatting
lib/backpex/ecto/amount_type.ex Removed internal Money type implementation
test/ecto/amount_type_test.exs Removed tests for the deleted Amount type
package.json Added imask dependency
mix.exs Removed money dependency from main project
demo/ files Updated demo to use external Money library with proper configuration

Base automatically changed from feature/js-bundle to develop August 22, 2025 10:49
@Flo0807 Flo0807 requested review from pehbehbeh and krns August 22, 2025 12:54
@Flo0807 Flo0807 marked this pull request as ready for review August 22, 2025 12:54
end

@impl Backpex.Field
def search_condition(schema_name, field_name, search_string) do
Copy link
Collaborator Author

@Flo0807 Flo0807 Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still, the UX when searching for currency is not very good, as you have to search for integer values. We could add another field_option that is used in this function to convert the search string into an integer. (However, we would need to modify the function to receive the field options...)

WDYT? @krns @pehbehbeh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the same apply for Filters like a Range filter?

To have some kind of options to transform the search term sounds good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the same problem when using a range filter. The search_condition is not used there, so I guess we should leave it like it is and find a solution that covers both filters and field search.

Copy link
Member

@krns krns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I only have one question about the default values.

Have you been able to test the changes of #1359 yet?

Flo0807 and others added 2 commits August 22, 2025 15:27
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@Flo0807 Flo0807 force-pushed the feature/1280-improve-currency-field branch from 247debd to 1c81961 Compare August 22, 2025 13:28
@Flo0807
Copy link
Collaborator Author

Flo0807 commented Aug 22, 2025

Overall, I only have one question about the default values.

Have you been able to test the changes of #1359 yet?

Yes, it works.

@Flo0807 Flo0807 changed the title Improve Backpex.Fields.Currency Use masked input for Backpex.Fields.Currency Sep 19, 2025
Comment on lines +28 to +51
price: %{
module: Backpex.Fields.Currency,
label: "Price",
unit: "",
unit_position: :after,
radix: ",",
thousands_separator: "."
},
...
]
end
```

See [field-specific options](`Backpex.Fields.Currency`) for default values.

2. Configure defaults for `money` in your `config/config.exs`

```elixir
config :money,
default_currency: :EUR,
separator: ".",
delimiter: ",",
symbol_on_right: true,
symbol_space: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align config keys:

  • separator vs. thousands_separator
  • delimiter vs. radix
  • symbol_on_right vs. unit_position
  • symbol_space not available on field level?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, got it.. thats the money config vs. backpex config.. hmhmh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change A breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Money dependency conflicts with ExMoney dependency in project
3 participants